package com.java65;

import java.util.ArrayList;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class NewsListTest {
    public static void main(String[] args) {
        NewsList title1 = new NewsList(1,"长城","author1");
        NewsList title2 = new NewsList(2,"天安门","author2");
        NewsList title3 = new NewsList(3,"故宫","author3");

        ArrayList list = new ArrayList();
        list.add(title1);
        list.add(title2);
        list.add(title3);
        System.out.println("新闻有"+list.size()+"条");
        System.out.println("------------------------------");

        for (int i = 0; i < list.size(); i++) {
            NewsList title = (NewsList)list.get(i);
            System.out.println(title.getTitle());
        }

        System.out.println("------------------------------");
        for (Object obj:list) {
            NewsList title = (NewsList)obj;
            System.out.println(title.getTitle());
        }
    }
}
class NewsList{
    int id;
    String title;
    String author;

    public NewsList() {
    }

    public NewsList(int id, String title, String author) {
        this.id = id;
        this.title = title;
        this.author = author;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }
}